package com.tangx.kafka.listener;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * Kafka主题消费者监听器
 */
@Component
public class ConsumerListener {


    @KafkaListener(topics = "myTopic")
    public void pollMsg(ConsumerRecord<String,String> consumerRecord){
        Optional<ConsumerRecord<String, String>> optional = Optional.ofNullable(consumerRecord);
        optional.ifPresent(x-> System.out.println(x.key() + "===" + x.value() + "===" + x.offset()));

        //System.out.println(consumerRecord.key() + "===" + consumerRecord.value());
    }

}
